package com.molyfun.parents.utils;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.molyfun.parents.MFPApplication;
import com.molyfun.parents.R;

public class UIUtils {

	private static Toast mToast;

	public static void showToast(Context context, String msg){
		if(mToast == null){
			mToast = new Toast(MFPApplication.sInstance);
		}
		if(context == null){
			return;
		}
		if(MFPApplication.isEmui){
			Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
		}else{
			View view = LayoutInflater.from(context).inflate(
					R.layout.view_transient_notification, null);
			TextView tv = (TextView) view.findViewById(android.R.id.message);
			tv.setText(msg);
			mToast.setView(view);
			mToast.setDuration(Toast.LENGTH_SHORT);
			mToast.setGravity(Gravity.FILL_HORIZONTAL|Gravity.TOP, 0, 0);
			mToast.show();
		}
	}

	public static void showToast(Context context, String msg, int period){
		if(mToast == null){
			mToast = new Toast(MFPApplication.sInstance);
		}
		View view = LayoutInflater.from(context).inflate(
				R.layout.view_transient_notification, null);
		TextView tv = (TextView) view.findViewById(android.R.id.message);
		tv.setText(msg);
		mToast.setView(view);
		mToast.setDuration(period);
		mToast.setGravity(Gravity.FILL_HORIZONTAL|Gravity.TOP, 0, 0);
		mToast.show();
	}

}
